package cc.flyflow.web.controller.sys;

import cc.flyflow.biz.sys.entity.Message;
import cc.flyflow.biz.sys.service.IMessageService;
import cc.flyflow.common.config.NotWriteLogAnno;
import cc.flyflow.common.dto.MessageDto;
import cc.flyflow.common.dto.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 消息控制器
 *
 * @author Jyl
 */
@RestController
@RequestMapping(value = {"message"})
public class MessageController
{

    @Resource
    private IMessageService messageService;

    /**
     * 获取未读数量
     */
    @NotWriteLogAnno(printResultLog = false)
    @SneakyThrows
    @GetMapping("/unreadNum")
    public R queryUnreadNum(Long lastId)
    {
        return messageService.queryUnreadNum(lastId);
    }

    /**
     * 查询列表
     *
     * @param pageDto
     * @return
     */
    @PostMapping("queryList")
    public R<Page<Message>> queryList(@RequestBody MessageDto pageDto)
    {
        return messageService.queryList(pageDto);
    }

    /**
     * 删除消息
     *
     * @param messageDto
     * @return
     */
    @DeleteMapping("delete")
    public R delete(@RequestBody MessageDto messageDto)
    {
        return messageService.delete(messageDto);
    }

    /**
     * 置为已读
     *
     * @param messageDto
     * @return
     */
    @PostMapping("read")
    public R read(@RequestBody MessageDto messageDto)
    {
        return messageService.read(messageDto);
    }

    /**
     * 全部已读
     *
     * @return
     */
    @PostMapping("readAll")
    public R readAll()
    {
        return messageService.readAll();
    }
}
